package com.stylefeng.guns.core.util.clm;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 
/**
 * WS 接口对接公用类
 * @author RenWeigang
 *
 */
public class HttpTools {
	private static Log log = LogFactory.getLog(HttpTools.class);
	//private static final String URL = ConfigManager.create().getProperty("ws.traing.gensee.url");
	private static final String URL = "";

	/**
	 * get请求
	 * @param path 例如： /room/info
	 * @param map 传入map
	 * @return
	 */
	public static String sendHttpClientGet(String path,Map<String, String> map){
		
		StringBuilder sb = new StringBuilder(validateHttpPath(path));
		sb.append("?1=1");
		if(map!=null){
			for(Map.Entry<String, String> entry : map.entrySet()){
				sb.append("&"+entry.getKey()+"="+entry.getValue());
			}
		}
		log.info("requres==="+sb.toString());
		String result=Https.httpRequest(sb.toString(), "GET", null);
		log.info("response==="+result);
		return result;
	}
	
	
	/**
	 * 
	 * @param path
	 * @param key
	 * @param value
	 * @return
	 */
	public static String sendHttpClientGet(String path,String key,String value){
		Map<String, String> map = new HashMap<String,String>();
		map.put(key, value);
		return sendHttpClientGet(path,map);
	}
	
	/**
	 * 第三方http开头检测
	 * @param path
	 * @return
	 */
	private static String validateHttpPath(String path){
		if(!path.startsWith("http") && path.startsWith("/")){
			path=URL+path;
		}else if(!path.startsWith("http") && !path.startsWith("/")){
			path=URL+"/"+path;
		}
		return path;
	}
}
